package edu.thu.studio.ormdesigner.outline.command;

import edu.thu.studio.ormdesigner.common.AbstractCommand;
import edu.thu.studio.ormdesigner.model.ORMModel;
import edu.thu.studio.ormdesigner.model.domain.Domain;
import edu.thu.studio.ormdesigner.model.domain.DomainSet;

public class UpdateDomainCommand extends AbstractCommand {
    
    private DomainSet domains;
    
    private Domain oldDomain;
    
    private Domain newDomain;
    
    public UpdateDomainCommand(ORMModel model, Domain oldDiagram, Domain newDiagram) {
        this.domains = model.getDomains();
        this.oldDomain = oldDiagram;
        this.newDomain = newDiagram;
    }
    
    /**
     * {@inheritDoc}
     */
    @Override
    protected void doExecute() {
        this.domains.merge(newDomain);
    }
    
    /**
     * {@inheritDoc}
     */
    @Override
    protected void doUndo() {
        this.domains.remove(newDomain);
        this.domains.addObject(oldDomain);
        this.domains.refresh();
    }
}
